<?php
namespace app\common\model;
use think\Request;

/**
 * 站点订单模型
 */
class WebOrder extends BaseModel
{
    protected $name = 'web_order';
	
	/**
     * 支付状态
     */
    public function getPayStatusAttr($value)
    {
        $status = [10 => '失败', 20 => '成功'];
        return ['text' => $status[$value], 'value' => $value];
    }
	
	/**
     * 订单类型
     */
    public function getOrderTypeAttr($value)
    {
        $status = [10 => '充值', 20 => '扣费'];
        return ['text' => $status[$value], 'value' => $value];
    }

	/**
     * 获取列表
     */
    public function getList()
    {
		//删除超过两个小时未支付的订单
		$this->useGlobalScope(false)
			->where('pay_status' ,'=',10)
			->where('create_time' ,'<=',time()-7200)
			->delete();
         // 执行查询
        $list = $this->useGlobalScope(false)
			->order('web_order_id','desc')
            ->paginate(15, false, ['query' => Request::instance()->request()]);
        return $list;
    }

	/**
     * 详情
     */
    public static function detail($web_order_id)
    {
        return self::useGlobalScope(false)->where('web_order_id',$web_order_id)->find();
    }
}
